import judDataType from './datatype.js'

let initData = {
    object: () => new Object(),
    array: () => new Array()
}

let baseType = ['null', 'string', 'number', 'undefined', 'function', 'boolean']

export default function deepClone(data) {
    let dataType = judDataType(data);
    if (baseType.includes(dataType)) {
        return data;
    }
    let newData = initData[dataType] instanceof Function ? initData[dataType]() : {};
    for (let key in data) {
        newData[key] = deepClone(data[key]);
    }
    return newData;
}